var count = 0;
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    width: {
      type: Number,    
      value: 50,
    },
    height: {
      type: Number,
      value: 50,
    },
    key:{
      type: Number,
      value: 5,
    },
    isFix:{
      type: Number,
      value: 1,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    stars: [0, 1, 2, 3, 4],
    normalSrc: '/assets/images/no-star.png',
    selectedSrc: '/assets/images/full-star.png',
    halfSrc: '/assets/images/half-star.png',
    key: 0,//评分
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //点击左边,半颗星
    selectLeft: function (e) {
      console.log('selectLeft')
      if (this.data.isFix){
        return
      }
      var key = e.currentTarget.dataset.key
      if (this.data.key == 0.5 && e.currentTarget.dataset.key == 0.5) {
        //只有一颗星的时候,再次点击,变为0颗
        key = 0;
      }
      count = key
      this.setData({
        key: key
      })

    },
    //点击右边,整颗星
    selectRight: function (e) {
      console.log('selectRight')
      if (this.data.isFix) {
        return
      }
      var key = e.currentTarget.dataset.key
      count = key
      this.setData({
        key: key
      })
    },
    startRating: function (e) {

      wx.showModal({
        title: '分数',
        content: "" + count,
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          }
        }
      })
    }
  }
})
